package com.njust.diary.util;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
//将对象转成json字符串相应给ajax
public class JsonUtil {
    public static void toJson(HttpServletResponse resp,Object result){
        try{

            resp.setContentType("application/json;charset=UTF-8");
            PrintWriter out =resp.getWriter();
            String json = JSON.toJSONString(result);
            out.write(json);
            out.close();



        }catch(Exception e){
           e.printStackTrace();
        }







    }


}
